package com.rcd.viatornisl.android;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

import com.google.analytics.tracking.android.EasyTracker;
import com.rcd.viatornisl.android.fragment.EstablishmentFragment;
import com.rcd.viatornisl.android.fragment.NavigationDrawerFragment;

public class StartActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks {

	private NavigationDrawerFragment _NavigationDrawerFragment;
	private CharSequence _Title;
		
	public void restoreActionBar() {
		// Get the action bar
        ActionBar actionBar = getSupportActionBar();
        
        // Setup the action bar
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(this._Title);
    }
	
	@Override
	protected void onStart() {
		// Default operations
		super.onStart();
		
		// Track with Google Analytics
		EasyTracker.getInstance().activityStart(this);
	}
	
	@Override
	protected void onStop() {
		// Default operations
		super.onStop();

		// Untrack with Google Analytics
		EasyTracker.getInstance().activityStop(this);
	}
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
		// Default operations
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.start_activity);

        // Setup and fill the objects
        this._Title = this.getTitle();
        this._NavigationDrawerFragment = ((NavigationDrawerFragment)this.getSupportFragmentManager().findFragmentById(R.id.navigation_drawer));
        this._NavigationDrawerFragment.setup(R.id.navigation_drawer, ((DrawerLayout)this.findViewById(R.id.drawer_layout)));
    }
	
	@Override
	public void onNavigationDrawerItemSelected(int position, Bundle parameters) {
		// Local variables
        EstablishmentFragment establishmentFragment = new EstablishmentFragment();
        
		// Get the fragment manager
		FragmentManager fragmentManager = this.getSupportFragmentManager();
        
		// Set the arguments
		establishmentFragment.setArguments(parameters);
 		
 		// Execute the fragment
		fragmentManager.beginTransaction().replace(R.id.container, establishmentFragment).commit();
		
		/*TODO: Maybe remove this later.
		// Select the users option
		switch (position) {
			case 0:
				// Execute the fragment
				fragmentManager.beginTransaction()
					.replace(R.id.container, establishmentFragment)
					.commit();
				break;
				
			case 1:
				// Execute the fragment
				fragmentManager.beginTransaction()
					.replace(R.id.container, establishmentFragment)
					.commit();
				break;
				
			case 2:
				// Execute the fragment
				fragmentManager.beginTransaction()
					.replace(R.id.container, establishmentFragment)
					.commit();
				break;
				
			case 3:
				// Execute the fragment
				fragmentManager.beginTransaction()
					.replace(R.id.container, establishmentFragment)
					.commit();
				break;
	
			default:
				// Log on error
				Log.e("void onNavigationDrawerItemSelected(int position, Bundle parameters)", "Invalid Option");
				break;
		}
		*/
	}	
	
}
